﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using Utilities;
using Bussiness;
using TerraExplorerX;

namespace UI
{
    public partial class RouteHistoryForm : KryptonForm
    {
        private ISGWorld61 sgworld;
        public RouteHistoryForm()
        {
            EsriUtility.InitEsriLicense();       
            InitializeComponent();
            //this.sgworld = sgw;
            sgworld = new SGWorld61();
        }
        private void RouteHistoryForm_Load(object sender, EventArgs e)
        {
            InitializeCbox_CRCode();
        }
        private void label1_Click(object sender, EventArgs e)
        {          
        }
        private void InitializeCbox_CRCode()
        {
            PropertyQuery pq = new PropertyQuery();
            List<int> crCodes = pq.QueryAllCR();
            crCodes.Sort();
            for (int i = 0; i < crCodes.Count; i++)
            {                
                string str = "知明1-" + crCodes[i].ToString();
                this.CBox_CRCode.Items.Add(str);
            }
            //this.CBox_CRCode.SelectedIndex = 0;
            this.CBox_CRCode.SelectedItem = "知明1-401";
        }

        private void Btn_Find_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = null;
            string[] str = this.CBox_CRCode.SelectedItem.ToString().Split('-');
            int CrCode = Convert.ToInt32(str[1]);
            DateTime startTime = Tpk_Start.Value;
            DateTime endTime = Tpk_End.Value;
            DataTable dt = new DataTable();

            BestRoutesManager br = new BestRoutesManager();
            dt = br.FindRouteHistory(CrCode, startTime, endTime);
            this.dataGridView1.DataSource = dt;
            SetDataGridView();

        }

        private void SetDataGridView()
        {
            dataGridView1.Columns[0].Visible = false;
            dataGridView1.Columns[3].Visible = false;
            dataGridView1.Columns[4].Visible = false;
            dataGridView1.Columns[5].Visible = false;

            dataGridView1.Columns[1].HeaderText = "疏散组";
            dataGridView1.Columns[2].HeaderText = "教室编码";
            dataGridView1.Columns[6].HeaderText = "发布时间";
            dataGridView1.Columns[7].HeaderText = "疏散情况";
            dataGridView1.Columns[8].HeaderText = "权重";
            dataGridView1.Columns[9].HeaderText = "总耗费";
        }

        
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
           // MessageBox.Show(dataGridView1[e.RowIndex,e.ColumnIndex].Value.ToString());
            int CrCode=Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[2].Value);
            int GroupNo = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value);
            SLHelper helper = new SLHelper();

            string modelUrl = Application.StartupPath + @"\vehicle\man.xpc";            
            helper._ModelURL = modelUrl;
            helper._Speed = 3;
            helper._ActionCode = ActionCode.AC_FOLLOWCOCKPIT;
            
            helper.RunByRoute(CrCode, GroupNo);
        }

        

       

       
    }
}
